package com.ruoyi.web.controller.zdgl;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.core.date.DateUtil;
import com.ruoyi.zdgl.domain.YwGsxxb;
import com.ruoyi.zdgl.service.IYwGsxxbService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zdgl.domain.YwXmxxb;
import com.ruoyi.zdgl.service.IYwXmxxbService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 项目信息Controller
 * 
 * @author chrui
 * @date 2024-07-25
 */
@RestController
@RequestMapping("/zdgl/xmxxb")
public class YwXmxxbController extends BaseController
{
    @Autowired
    private IYwXmxxbService ywXmxxbService;

    /**
     * 公司信息
     */
    @Autowired
    private IYwGsxxbService ywGsxxbService;

    /**
     * 获取根据公司编号获取项目信息id列表
     */
    @GetMapping("/getXmmcByGsbh/{gsbh}")
    public AjaxResult getXmmcByGsbh(@PathVariable("gsbh") Long gsbh)
    {
        return success(ywXmxxbService.getXmmcByGsbh(gsbh));
    }
    /**
     * 查询项目信息表
     */
    @GetMapping("/getGetXmxxIdList")
    public AjaxResult getGetXmxxIdList()
    {
        return success(ywXmxxbService.selectYwXmxxbList(null));
    }
    /**
     * 查询公司信息表
     */
    @GetMapping("/getGetGsxxIdList")
    public AjaxResult getGetGsxxIdList()
    {
        List<YwGsxxb> ywGsxxbList = ywGsxxbService.selectYwGsxxbList(null);
        return success(ywGsxxbList);
    }

    /**
     * 查询项目信息列表
     */
    @PreAuthorize("@ss.hasPermi('zdgl:xmxxb:list')")
    @GetMapping("/list")
    public TableDataInfo list(YwXmxxb ywXmxxb)
    {
        startPage();
        List<YwXmxxb> list = ywXmxxbService.selectYwXmxxbList(ywXmxxb);
        TableDataInfo dataTable = getDataTable(list);
        return dataTable;
    }

    /**
     * 导出项目信息列表
     */
    @PreAuthorize("@ss.hasPermi('zdgl:xmxxb:export')")
    @Log(title = "项目信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YwXmxxb ywXmxxb)
    {
        List<YwXmxxb> list = ywXmxxbService.selectYwXmxxbList(ywXmxxb);
        ExcelUtil<YwXmxxb> util = new ExcelUtil<YwXmxxb>(YwXmxxb.class);
        util.exportExcel(response, list, "项目信息数据");
    }

    /**
     * 获取项目信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('zdgl:xmxxb:query')")
    @GetMapping(value = "/{xmbh}")
    public AjaxResult getInfo(@PathVariable("xmbh") Long xmbh)
    {
        return success(ywXmxxbService.selectYwXmxxbByXmbh(xmbh));
    }

    /**
     * 新增项目信息
     */
    @PreAuthorize("@ss.hasPermi('zdgl:xmxxb:add')")
    @Log(title = "项目信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YwXmxxb ywXmxxb)
    {
        ywXmxxb.setCreateBy(getUsername());
        return toAjax(ywXmxxbService.insertYwXmxxb(ywXmxxb));
    }

    /**
     * 修改项目信息
     */
    @PreAuthorize("@ss.hasPermi('zdgl:xmxxb:edit')")
    @Log(title = "项目信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YwXmxxb ywXmxxb)
    {
        ywXmxxb.setUpdateBy(getUsername());
        return toAjax(ywXmxxbService.updateYwXmxxb(ywXmxxb));
    }

    /**
     * 删除项目信息
     */
    @PreAuthorize("@ss.hasPermi('zdgl:xmxxb:remove')")
    @Log(title = "项目信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{xmbhs}")
    public AjaxResult remove(@PathVariable Long[] xmbhs)
    {
        return toAjax(ywXmxxbService.deleteYwXmxxbByXmbhs(xmbhs));
    }
}
